package com.chris.homecare
{
	import com.chris.homecare.components.HeaderComponent;
	import com.chris.homecare.components.LeftDrawer;
	import com.chris.homecare.utils.ShowNativeAlert;
	
	import feathers.controls.Drawers;
	import feathers.controls.List;
	import feathers.events.FeathersEventType;
	
	import starling.events.Event;
	
	public class AppScreen extends Drawers
	{
		private var menu:List;
		public static var instance:AppScreen;
		
		private var leftDrawer:LeftDrawer;
		public function AppScreen()
		{
			super();
			instance = this;
		}
		
		override protected function initialize():void
		{
			var halfWidth:int = stage.stageWidth/2;
			
			this.content = new Main();
			this.addEventListener(HeaderComponent.TRIGGER_ACTIONSHEET, onActionSheetTrigger);
			this.addEventListener(FeathersEventType.BEGIN_INTERACTION, onBeginIntraction);
			
			leftDrawer = new LeftDrawer();
			leftDrawer.width = stage.stageWidth*2/3;
			this.rightDrawer = leftDrawer;
			var nativeAlert:ShowNativeAlert = new ShowNativeAlert();
			this.openGesture = Drawers.OPEN_GESTURE_NONE;
		}
		
		private function onBeginIntraction(event:Event):void
		{
			//this.toggleRightDrawer();
			trace("fhghfh");
		}
		
		public function menuEventHandler():void
		{
			this.toggleRightDrawer();
			this.addEventListener(Event.CLOSE, menuCloseHandler);
		}
		
		private function menuCloseHandler():void
		{
			var mainScreen:Main = this.content as Main;
			var event:Event = new Event(Event.COMPLETE, false, {page:leftDrawer.menu.selectedItem.screen});
			mainScreen.mainMenuHandler(event);
			this.removeEventListener(Event.CLOSE, menuCloseHandler);
		}
		
		private function onActionSheetTrigger(event:Event):void
		{
			this.toggleRightDrawer();
		}
		
		public static function makeGestureAvailable():void
		{
			instance.openGesture = Drawers.OPEN_GESTURE_DRAG_CONTENT_EDGE;
		}
		
		public static function makeGestureUnAvailable():void
		{
			instance.openGesture = Drawers.OPEN_GESTURE_NONE;
		}
		
	}
}